package com.okay.Media

import android.media.MediaPlayer
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.fragment.app.FragmentActivity
import com.okay.testclass.R

/**
 * 测试音频文件时长的activity
 */
class TestMedia : FragmentActivity() {
    private val audioUrl = "http://aud.okjiaoyu.cn/aud_7kfs510gzzsw.m4a"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_media)


        val mediaPlayer = MediaPlayer()
        mediaPlayer.setDataSource(audioUrl)
        mediaPlayer.prepare()


        Log.d("时长","${mediaPlayer.duration}")
        findViewById<TextView>(R.id.media_text).text = "音频 $audioUrl 时长 : "+ (mediaPlayer.duration).toString()
    }
}